package com.yvon.maple.auth.authorization.model;

import com.yvon.maple.cloud.api.system.dto.SecurityUserDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class SecurityUser extends User implements Serializable {

    /**
     * ID
     */
    private Long id;



    public SecurityUser(SecurityUserDTO securityUserDTO ,Collection<? extends GrantedAuthority> authorities) {
        super(securityUserDTO.getUsername(),
                Objects.isNull(securityUserDTO.getPassword()) ? "12345" : securityUserDTO.getPassword() ,
                securityUserDTO.getEnabled(),
                securityUserDTO.getAccountNonExpired(),
                securityUserDTO.getCredentialsNonExpired(),
                securityUserDTO.getAccountNonLocked(),
                authorities);
        this.id = securityUserDTO.getId();
    }
}
